package com.tridoron.reggie.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class TimeUtils {

    public static LocalDateTime parseStringToDateTime(String dateTimeString) {
        try {
            // 对URL编码进行解码
            String decodedDateTimeString = URLDecoder.decode(dateTimeString, "UTF-8");
            System.out.println("decodedDateTimeString = " + decodedDateTimeString);
            // 定义日期时间的格式，根据你的实际格式进行调整
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

            // 将解码后的字符串转换为LocalDateTime对象
            LocalDateTime dateTime = LocalDateTime.parse(decodedDateTimeString, formatter);

            return dateTime;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            // 解码异常时，返回null或者抛出异常，具体处理根据实际情况来定
            return null;
        }
    }
}